package com.example.happiness.service.user.Impl;

import com.example.happiness.constant.Message;
import com.example.happiness.mapper.FeedbackMapper;
import com.example.happiness.mapper.OrderDispatchMapper;
import com.example.happiness.mapper.OrderMapper;
import com.example.happiness.pojo.Feedback;
import com.example.happiness.pojo.OrderDispatch;
import com.example.happiness.pojo.generalDTO.OrderStateDTO;
import com.example.happiness.pojo.uservo.UserReviewsVO;
import com.example.happiness.service.user.UserFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserFeedbackServiceImpl implements UserFeedbackService {

    @Autowired
    FeedbackMapper feedbackMapper;
    @Autowired
    OrderDispatchMapper orderDispatchMapper;
    @Autowired
    OrderMapper orderMapper;

    @Transactional
    public void addFeedback(Feedback feedback) {
        OrderDispatch orderDispatch = orderDispatchMapper.findbyorderid(feedback.getOrderid());
        OrderStateDTO orderStateDTO = new OrderStateDTO();
        orderStateDTO.setOrderid(feedback.getOrderid());
        orderStateDTO.setState(Message.ELEVEN);
        orderMapper.updataOrderState(orderStateDTO);
        feedback.setEid(orderDispatch.getEid());
        feedbackMapper.insert(feedback);
    }

    public List<UserReviewsVO> getFeedback(String userid) {
        return feedbackMapper.getFeedback(userid);
    }
}
